package com.hospital.config.handle;

import common.core.util.CommonUtil;
import common.core.util.CustomizeRuntimeException;
import common.core.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.smartcardio.CommandAPDU;

/**
 * 全局异常处理
 * @author xhl
 */
@Slf4j
//@RestControllerAdvice
public class CustomizeRuntimeExceptionHandle {

    @ExceptionHandler(CustomizeRuntimeException.class)
    @ResponseStatus(value = HttpStatus.OK)
    public Result<Object> handleXCloudException(CustomizeRuntimeException e) {
        String msg = null;
        if (CommonUtil.isNotEmpty(e)) {
            msg = e.getMessage();
            log.error(msg);
        }

        return Result.fail(msg);
    }

    @ExceptionHandler(Exception.class)
    @ResponseStatus(value = HttpStatus.OK)
    public Result<Object> handleException(Exception e) {
        String msg = null;
        if (CommonUtil.isNotEmpty(e)) {
            msg = e.getMessage();
            log.error(msg);
        }
        return Result.fail(msg);
    }
}
